package xyz.scootaloo.mono.security.util

import cn.hutool.jwt.JWT
import org.junit.Test
import xyz.scootaloo.mono.base.lang.TestDsl
import java.util.*

/**
 * @author flutterdash@qq.com
 * @since 2021/7/30 18:57
 */
class HutoolJwtTest : TestDsl {

    @Test
    fun sample() {
        val token = sign().log()!!
        val jwt = JWT.of(token)
        jwt.getHeader("name").log()
        jwt.getPayload("password").log()
        jwt.setKey(key).verify().log()
    }

    private fun sign(): String {
        return JWT.create().run {
            setHeader("name", "admin")
            setPayload("password", "123456")
            setPayload("ok", true)
            setKey(key)
            setIssuedAt(Date())
            sign()
        }
    }

    private fun signWithSinger(key: String): String {
        return ""
    }

    private val key = "1234567890".encodeToByteArray()

}
